{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# 📊 领导力成长模型：谨慎者、机变者、勇毅者演化模拟\n",
        "\n",
        "基于能力因果图（DAG）与状态转移矩阵的动态系统模型，模拟三类领导者的能力成长路径。\n",
        "\n",
        "- **谨慎者**：低眉察言 → 判断力驱动\n",
        "- **机变者**：左右观色 → 沟通力驱动\n",
        "- **勇毅者**：器宇轩昂 → 引领力驱动"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "!pip install numpy matplotlib seaborn pandas"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "import matplotlib.pyplot as plt\n",
        "import seaborn as sns\n",
        "import pandas as pd\n",
        "\n",
        "# 设置中文字体支持\n",
        "plt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS', 'DejaVu Sans']\n",
        "plt.rcParams['axes.unicode_minus'] = False"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 1. 定义状态转移矩阵 $ A $（9x9）"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 能力顺序：f1~f9 对应 亲和、沟通、执行、判断、决策、组织、感召、引领、领导\n",
        "A = np.array([\n",
        "    [0.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2],  # f1: 亲和 ← 自我 + 领导反馈\n",
        "    [0.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],  # f2: 沟通 ← 亲和\n",
        "    [0.0, 0.5, 0.0, 0.0, 0.7, 0.6, 0.0, 0.0, 0.0],  # f3: 执行 ← 沟通,决策,组织\n",
        "    [0.0, 0.6, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],  # f4: 判断 ← 沟通\n",
        "    [0.0, 0.0, 0.0, 0.9, 0.0, 0.0, 0.0, 0.0, 0.0],  # f5: 决策 ← 判断\n",
        "    [0.0, 0.0, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],  # f6: 组织 ← 执行\n",
        "    [0.3, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],  # f7: 感召 ← 亲和+沟通\n",
        "    [0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.6, 0.0, 0.0],  # f8: 引领 ← 决策+感召\n",
        "    [0.0, 0.0, 0.3, 0.0, 0.0, 0.5, 0.4, 0.7, 0.0]   # f9: 领导 ← 执行,组织,感召,引领\n",
        "])\n",
        "\n",
        "print(\"状态转移矩阵 A 已定义 (9x9):\")\n",
        "pd.DataFrame(A, \n",
        "             index=[f'f{i}({n})' for i, n in enumerate(['亲和','沟通','执行','判断','决策','组织','感召','引领','领导'],1)],\n",
        "             columns=[f'←f{i}' for i in range(1,10)]\n",
        "            ).round(1)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 2. 定义三类人的初始能力向量"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "names = ['亲和力', '沟通力', '执行力', '判断力', '决策力', \n",
        "         '组织力', '感召力', '引领力', '领导力']\n",
        "\n",
        "# 谨慎者：低眉察言 → 判断力强\n",
        "v0_cautious = np.array([6, 7, 6, 9, 5, 6, 4, 5, 5])\n",
        "\n",
        "# 机变者：左右观色 → 沟通力强\n",
        "v0_adaptive = np.array([8, 9, 6, 6, 7, 6, 7, 6, 6])\n",
        "\n",
        "# 勇毅者：器宇轩昂 → 引领力强\n",
        "v0_bold = np.array([5, 6, 8, 7, 9, 7, 8, 9, 7])\n",
        "\n",
        "# 汇总为 DataFrame 查看\n",
        "df_init = pd.DataFrame({\n",
        "    '谨慎者': v0_cautious,\n",
        "    '机变者': v0_adaptive,\n",
        "    '勇毅者': v0_bold\n",
        "}, index=names)\n",
        "\n",
        "print(\"初始能力分布：\")\n",
        "df_init"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 3. 模拟演化过程（T=10 步）"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "T = 10\n",
        "\n",
        "# 初始化历史记录\n",
        "history = {\n",
        "    '谨慎者': np.zeros((T+1, 9)),\n",
        "    '机变者': np.zeros((T+1, 9)),\n",
        "    '勇毅者': np.zeros((T+1, 9))\n",
        "}\n",
        "\n",
        "history['谨慎者'][0] = v0_cautious\n",
        "history['机变者'][0] = v0_adaptive\n",
        "history['勇毅者'][0] = v0_bold\n",
        "\n",
        "# 时间迭代\n",
        "for t in range(T):\n",
        "    for key in history:\n",
        "        history[key][t+1] = A @ history[key][t]\n",
        "        # 饱和限制\n",
        "        history[key][t+1] = np.clip(history[key][t+1], 0, 10)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 4. 绘图1：领导力（$f_9$）成长曲线"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "plt.figure(figsize=(10, 6))\n",
        "\n",
        "for name, data in history.items():\n",
        "    color = 'blue' if name == '谨慎者' else 'orange' if name == '机变者' else 'red'\n",
        "    plt.plot(range(T+1), data[:, 8], 'o-' if name=='谨慎者' else 's-' if name=='机变者' else '^-', \n",
        "             label=name, color=color, markersize=6)\n",
        "\n",
        "plt.xlabel('时间步', fontsize=12)\n",
        "plt.ylabel('领导力水平 (f9)', fontsize=12)\n",
        "plt.title('三类人领导力成长路径对比', fontsize=14, fontweight='bold')\n",
        "plt.legend(fontsize=12)\n",
        "plt.grid(True, alpha=0.3)\n",
        "plt.ylim(0, 10)\n",
        "plt.xticks(range(T+1))\n",
        "plt.tight_layout()\n",
        "plt.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 5. 绘图2：能力演化热力图"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "def plot_heatmap(data, title, cmap):\n",
        "    df = pd.DataFrame(data, \n",
        "                      columns=[f't{i}' for i in range(T+1)], \n",
        "                      index=names)\n",
        "    plt.figure(figsize=(10, 6))\n",
        "    sns.heatmap(df.T, annot=True, cmap=cmap, cbar=True,\n",
        "                fmt='.1f', annot_kws={\"size\": 10})\n",
        "    plt.title(title, fontsize=14)\n",
        "    plt.xlabel('能力维度')\n",
        "    plt.ylabel('时间步')\n",
        "    plt.tight_layout()\n",
        "    plt.show()\n",
        "\n",
        "# 分别绘制\n",
        "for name, data in history.items():\n",
        "    cmap = 'Blues' if name == '谨慎者' else 'Oranges' if name == '机变者' else 'Reds'\n",
        "    plot_heatmap(data, f'{name}：能力演化热力图', cmap)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 6. 输出最终领导力值"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "print(\"🔹 10步后领导力水平（f9）：\")\n",
        "results = {}\n",
        "for name, data in history.items():\n",
        "    final_leadership = data[T, 8]\n",
        "    results[name] = final_leadership\n",
        "    print(f\"  {name}: {final_leadership:.2f}\")\n",
        "\n",
        "# 排行榜\n",
        "winner = max(results, key=results.get)\n",
        "print(f\"\\n🏆 领导力最高者：{winner} ({results[winner]:.2f})\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 7. 进阶分析：能力均衡性（香农熵）"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "def entropy(vector):\n",
        "    \"\"\"计算能力分布的香农熵（归一化）\"\"\"\n",
        "    p = vector / vector.sum()\n",
        "    return -np.sum(p * np.log(p + 1e-8))\n",
        "\n",
        "print(\"\\n🔸 能力分布均衡性分析（熵值，越高越均衡）：\")\n",
        "for name, data in history.items():\n",
        "    final_vec = data[T]\n",
        "    H = entropy(final_vec)\n",
        "    print(f\"  {name}: {H:.3f}\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 8. 保存数据（可选）"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "# 保存为 CSV\n",
        "for name, data in history.items():\n",
        "    df_out = pd.DataFrame(data, columns=names)\n",
        "    df_out.to_csv(f'{name}_能力演化.csv', index=False)\n",
        "    print(f\"✅ 已保存 {name} 数据到 {name}_能力演化.csv\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## 📝 洞察总结\n",
        "\n",
        "1. **成长路径差异**：\n",
        "- 谨慎者：稳扎稳打，后期发力；\n",
        "- 机变者：初期快，但需防泡沫；\n",
        "- 勇毅者：起点高，但易失衡。\n",
        "\n",
        "2. **领导力奇点预警**：\n",
        "- 若感召力或决策力增长过快而判断力滞后，可能形成“自我强化泡沫”。\n",
        "\n",
        "3. **建议**：\n",
        "- 谨慎者：提升感召力；\n",
        "- 机变者：加强判断力；\n",
        "- 勇毅者：增强亲和力与倾听。\n",
        "\n",
        "> 🌟 真正的领导力，不是单项极致，而是系统动态平衡。"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}